# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import fields, models, api

import logging
_logger = logging.getLogger(__name__)


class Company(models.Model):
    _inherit = 'res.company'

    iot_project_ids = fields.One2many(
        'iot.project', 'company_id', string='Iot Projects')
    iot_gateway_ids = fields.One2many(
        'iot.gateway', 'company_id', string='Iot Gateways')
    iot_device_ids = fields.One2many(
        'iot.device', 'company_id', string='Iot Devices')
    iot_sensor_ids = fields.One2many(
        'iot.sensor', 'company_id', string='Iot Sensors')

class IotProject(models.Model):
    _name = "iot.project"
    _description = 'IotProject'
    _order = "name"

    name = fields.Char(index=True)
    code = fields.Char(index=True)
    user_id = fields.Many2one('res.users', 'User', 
        default=lambda self: self.env.uid, index=True)

    partner_id = fields.Many2one('res.partner', 'Partner', 
        related='user_id.partner_id', store=True, index=True)

    company_id = fields.Many2one('res.company', 'Company', 
        default=lambda self: self.env.company, index=True)

    gateway_ids = fields.One2many(
        'iot.gateway', 'project_id', string='Gateways')
    device_ids = fields.One2many('iot.device', 'project_id', string='Devices')
    sensor_ids = fields.One2many('iot.sensor', 'project_id', string='Sensors')

